package exadel.calc;

import java.util.Iterator;
import java.util.NoSuchElementException;
import java.util.Scanner;
import java.util.SortedMap;
import java.util.TreeMap;
import java.util.Map.Entry;

public class StartCalculator {

	/**
	 * @param args
	 **/
	public static void main(String[] args) {
	Scanner con = new Scanner(System.in);
		while(true){ 
			
			int money;
			int count;
				System.out.println("value of money:");
				money = con.nextInt();
				System.out.println("number of coins:");
				count = con.nextInt();
			
			BasicCalculator cal = new BasicCalculator(money,count);
			
			SortedMap<Integer, Integer> m = new TreeMap<Integer, Integer>();
			try {
				m.putAll(cal.calculator());
				System.out.println("result of a calculation:");
				Iterator<Entry<Integer, Integer>> it = m.entrySet().iterator();
			    while( it.hasNext() )
			    {
			        Entry<Integer, Integer> elem = it.next();
			        System.out.println(elem.getKey() + "  " + elem.getValue() + "\n");
			    }
			} catch(NullPointerException ex){
				System.out.println("1:the data with error(" + ex.getMessage() + ")");
			} catch(NoSuchElementException ex){
				System.out.println("2:the data with error(" + ex.getMessage() + ")");
			} catch(IllegalArgumentException ex){
				System.out.println("3:the data with error(" + ex.getMessage() + ")");
			} catch(IllegalStateException ex){
				System.out.println("4:the data with error(" + ex.getMessage() + ")");
			} catch (CalculatorFailedException ex) {
				ex.getMessage();
			}
			
		}		
	}

}
